﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Visual_CRUD_Plugins_EditPlugin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            verificaUser();
            try
            {
                String cod = Session["idselectplugins"].ToString();
                Plugins objeto = PluginsDAO.DSToList(PluginsDAO.select(" WHERE id=" + cod, " "))[0];
                tbdescription.Text = objeto.description;
                tblocalization.Text = objeto.localization;
                tbprocname.Text = objeto.procedurename;
                tbversion.Text = objeto.version;
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message);
            }
        }
    }
    protected void verificaUser()
    {
        VSDBM.Code.dto.User usuariologado = (VSDBM.Code.dto.User)HttpContext.Current.Session["usuariologado"];
        if (!(usuariologado.acessgroup == 1))
        {
            HttpContext.Current.Session["exception"] = "You are not authorized!";
            Response.Redirect("~/Visual/Errors/error.aspx");
        }
    }
    protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        Plugins objeto = new Plugins(int.Parse(Session["idselectplugins"].ToString()), tbdescription.Text, tbversion.Text, tblocalization.Text, tbprocname.Text, 1);
        if (PluginsDAO.edit(objeto) == "Updated!")
        {
            Response.Redirect("ListPlugin.aspx");
        }
      
    }
    protected void btdelete_click(object sender, ImageClickEventArgs e)
    {
        Plugins objeto = new Plugins(int.Parse(Session["idselectplugins"].ToString()), tbdescription.Text, tbversion.Text, tblocalization.Text, tbprocname.Text, 1);
        if (PluginsDAO.delete(objeto) == true)
        {
            Response.Redirect("ListPlugin.aspx");
        }
    }
}